/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package isvp.test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Node;

/**
 *
 * @author patsrik
 */
public class PrintClass {
    public static void printXML(Document d) {
        try {
            TransformerFactory factory = TransformerFactory.newInstance();
            Transformer transformer = factory.newTransformer();
            DOMSource domSource = new DOMSource(d);
            StreamResult sResult = new StreamResult(System.out);            
            transformer.transform(domSource, sResult);            
        } catch (TransformerException ex) {
        }        
    }
    
    public static void printNodeText(Node n) {
        System.out.println(n.getTextContent());
    }
    
    public static void printXML(InputStream iStream) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(iStream));
        StringBuilder sb = new StringBuilder();
        String line = null;
        try {
            while ((line = reader.readLine()) != null) {
              sb.append(line + "\n");
            }
        } catch (IOException ex) {
        }
        System.out.println(sb.toString());
    }
}